import requests
from hashlib import md5

def getText(image_path):
    username = 'hyp2010'
    password = '1qazxsw2'.encode('utf8')
    password = md5(password).hexdigest()
    soft_id = '907705 '
    base_params = {
        'user': username,
        'pass2': password,
        'softid': soft_id,
    }
    headers = {
        'Connection': 'Keep-Alive',
        'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
    }
    im = open(image_path, 'rb').read()
    params = {
    # 4004 1-4位纯数字，5000 不定长英文汉字 ，9202两个相同物体（滑动验证），9004 随机返回1-4个坐标，9104固定返回四个坐标
    # 更多请参考 http://www.chaojiying.com/price.html#table-item4
        'codetype': 4004,
    }
    params.update(base_params)
    files = {'userfile': ('ccc.jpg', im)}
    r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files,
                      headers=headers)
    res = r.json()['pic_str']
    res_list = []
    for i in res.split("|"):
        res_list.append(i)
    print(res_list)
    return res_list

# test(r"C:\Users\lujd\Pictures\test\code.png")